package cn.htsyb.synergy.maker.model;

import cn.htsyb.synergy.maker.config.Maker;
import cn.htsyb.synergy.maker.mapping.MysqlTypeMapping;
import cn.htsyb.synergy.maker.util.HumpUtil;

/**
 * 列元数据实体
 *
 * @author lakeside
 * @email hubin_yuan.410@hotmail.com
 * @date 2019-03-26
 */

public class MetaColumn {
    /**
     * 表类别
     */
    protected String tableCat;
    /**
     * 表模式
     */
    protected String tableSchem;
    /**
     * 表名称
     */
    protected String tableName;
    /**
     * 列名称
     */
    protected String columnName;
    /**
     * 来自 java.sql.Types 的 SQL 类型
     */
    protected Integer dataType;
    /**
     * 数据源依赖的类型名称，对于 UDT，该类型名称是完全限定的
     */
    protected String typeName;
    /**
     * 列的大小
     */
    protected Integer columnSize;
    /**
     * 未被使用
     */
    protected Integer bufferLength;
    /**
     * 小数部分的位数。对于 DECIMAL_DIGITS 不适用的数据类型，则返回 Null
     */
    protected Integer decimalDigits;
    /**
     * 基数（通常为 10 或 2）
     */
    protected Integer numPrecRadix;
    /**
     * 是否允许使用 NULL
     */
    protected Integer nullable;
    /**
     * 描述列的注释
     */
    protected String remarks;
    /**
     * 该列的默认值，当值在单引号内时应被解释为一个字符串
     */
    protected String columnDef;
    /**
     * 未使用
     */
    protected Integer sqlDataType;
    /**
     * 未使用
     */
    protected Integer sqlDatetimeSub;
    /**
     * 对于 char 类型，该长度是列中的最大字节数
     */
    protected Integer charOctetLength;
    /**
     * 表中的列的排序(从1开始)
     */
    protected Integer ordinalPosition;

    /**
     * 表的类别，它是引用属性的作用域
     */
    protected String scopeCatalog;
    /**
     * 表的模式，它是引用属性的作用域
     */
    protected String scopeSchema;
    /**
     * 表名称，它是引用属性的作用域
     */
    protected String scopeTable;
    /**
     * 不同类型或用户生成 Ref 类型、来自 java.sql.Types 的 SQL 类型的源类型
     */
    protected Integer sourceDataType;
    /**
     * ISO规则用来确定某一列的是否可为空(等同于NULLABLE的值:[ 0:'YES'; 1:'NO'; 2:''; ])
     * YES -- 该列可以有空值;
     * NO -- 该列不能为空;
     * 空字符串--- 不知道该列是否可为空
     */
    protected String isNullable;
    /**
     * 指示此列是否自动增加
     */
    protected String isAutoincrement;

    /**
     * 指示此列是否自动增加
     */
    protected Boolean isTableSchem;
    /**
     * 指示此列是生成列
     */
    protected Boolean isGeneratedColumn;
    /***/

    /*ext*/
    /**
     * 是否为主键
     */
    protected boolean hasPrimaryKey;
    /**
     * 字段大驼峰名称
     */
    protected String fieldName;
    /**
     * 字段小驼峰变量名称
     */
    protected String fieldVarName;
    /**
     * Java中数据类型
     */
    protected String fieldType;
    /**
     * Mybatis中数据类型
     */
    protected String mybatisJdbcType;

    /*grid*/
    /**
     * 是否在列表中 none hidden show
     */
    protected String gridDisplay = "";

    /*search*/
    /**
     * 是否在查询中 none hidden show
     */
    protected String searchDisplay = "";
    /**
     * 查询方式 EQ......
     */
    protected String searchCriteria = "";

    /*form*/
    /**
     * 是否在表单中 none hidden show
     */
    protected String formDisplay = "";

    public String getTableCat() {
        return tableCat;
    }

    public void setTableCat(String tableCat) {
        this.tableCat = tableCat;
    }

    public String getTableSchem() {
        return tableSchem;
    }

    public void setTableSchem(Boolean tableSchem) {
        isTableSchem = tableSchem;
    }

    public void setTableSchem(String tableSchem) {
        this.tableSchem = tableSchem;
    }

    public Boolean getGeneratedColumn() {
        return isGeneratedColumn;
    }

    public void setGeneratedColumn(Boolean generatedColumn) {
        isGeneratedColumn = generatedColumn;
    }

    public boolean isHasPrimaryKey() {
        return hasPrimaryKey;
    }

    public void setHasPrimaryKey(boolean hasPrimaryKey) {
        this.hasPrimaryKey = hasPrimaryKey;
        this.formDisplay = "hidden";
        this.gridDisplay = "hidden";
        this.searchDisplay = "hidden";
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldVarName() {
        return fieldVarName;
    }

    public void setFieldVarName(String fieldVarName) {
        this.fieldVarName = fieldVarName;
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public String getMybatisJdbcType() {
        return mybatisJdbcType;
    }

    public void setMybatisJdbcType(String mybatisJdbcType) {
        this.mybatisJdbcType = mybatisJdbcType;
    }

    public String getGridDisplay() {
        return gridDisplay;
    }

    public void setGridDisplay(String gridDisplay) {
        this.gridDisplay = gridDisplay;
    }

    public String getSearchDisplay() {
        return searchDisplay;
    }

    public void setSearchDisplay(String searchDisplay) {
        this.searchDisplay = searchDisplay;
    }

    public String getSearchCriteria() {
        return searchCriteria;
    }

    public void setSearchCriteria(String searchCriteria) {
        this.searchCriteria = searchCriteria;
    }

    public String getFormDisplay() {
        return formDisplay;
    }

    public void setFormDisplay(String formDisplay) {
        this.formDisplay = formDisplay;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
        this.fieldVarName = HumpUtil.convertToSmallHump(columnName, Maker.getInstance().getRegular().getHumpConvertChar());
        this.fieldName = HumpUtil.upperFirstChar(getFieldVarName());
    }

    public Integer getDataType() {
        return dataType;
    }

    public void setDataType(Integer dataType) {
        this.dataType = dataType;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
        setFieldType(MysqlTypeMapping.convertToJavaType(typeName, this.columnSize));
        setMybatisJdbcType(MysqlTypeMapping.convertToMyBatisType(typeName, this.columnSize));

    }

    public Integer getColumnSize() {
        return columnSize;
    }

    public void setColumnSize(Integer columnSize) {
        this.columnSize = columnSize;
    }

    public Integer getBufferLength() {
        return bufferLength;
    }

    public void setBufferLength(Integer bufferLength) {
        this.bufferLength = bufferLength;
    }

    public Integer getDecimalDigits() {
        return decimalDigits;
    }

    public void setDecimalDigits(Integer decimalDigits) {
        this.decimalDigits = decimalDigits;
    }

    public Integer getNumPrecRadix() {
        return numPrecRadix;
    }

    public void setNumPrecRadix(Integer numPrecRadix) {
        this.numPrecRadix = numPrecRadix;
    }

    public String getIsNullable() {
        return isNullable;
    }

    public void setIsNullable(String isNullable) {
        isNullable = isNullable;
    }

    public String getIsAutoincrement() {
        return isAutoincrement;
    }

    public void setIsAutoincrement(String isAutoincrement) {
        isAutoincrement = isAutoincrement;
    }

    public Integer getNullable() {
        return nullable;
    }

    public void setNullable(Integer nullable) {
        this.nullable = nullable;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getColumnDef() {
        return columnDef;
    }

    public void setColumnDef(String columnDef) {
        this.columnDef = columnDef;
    }

    public Integer getSqlDataType() {
        return sqlDataType;
    }

    public void setSqlDataType(Integer sqlDataType) {
        this.sqlDataType = sqlDataType;
    }

    public Integer getSqlDatetimeSub() {
        return sqlDatetimeSub;
    }

    public void setSqlDatetimeSub(Integer sqlDatetimeSub) {
        this.sqlDatetimeSub = sqlDatetimeSub;
    }

    public Integer getCharOctetLength() {
        return charOctetLength;
    }

    public void setCharOctetLength(Integer charOctetLength) {
        this.charOctetLength = charOctetLength;
    }

    public Integer getOrdinalPosition() {
        return ordinalPosition;
    }

    public void setOrdinalPosition(Integer ordinalPosition) {
        this.ordinalPosition = ordinalPosition;
    }

    public String getScopeCatalog() {
        return scopeCatalog;
    }

    public void setScopeCatalog(String scopeCatalog) {
        this.scopeCatalog = scopeCatalog;
    }

    public String getScopeSchema() {
        return scopeSchema;
    }

    public void setScopeSchema(String scopeSchema) {
        this.scopeSchema = scopeSchema;
    }

    public String getScopeTable() {
        return scopeTable;
    }

    public void setScopeTable(String scopeTable) {
        this.scopeTable = scopeTable;
    }

    public Integer getSourceDataType() {
        return sourceDataType;
    }

    public void setSourceDataType(Integer sourceDataType) {
        this.sourceDataType = sourceDataType;
    }
}
